namespace ASPNET.StarterKit.IssueTracker
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using ASPNET.StarterKit.IssueTracker.UserInterfaceLayer;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class ProjectDescription : UserControl, IEditProjectControl
    {
        [AccessedThroughProperty("dropProjectManager")]
        private PickSingleUser _dropProjectManager;
        [AccessedThroughProperty("lblError")]
        private Label _lblError;
        private int _ProjectId;
        [AccessedThroughProperty("RequiredFieldValidator1")]
        private RequiredFieldValidator _RequiredFieldValidator1;
        [AccessedThroughProperty("RequiredFieldValidator2")]
        private RequiredFieldValidator _RequiredFieldValidator2;
        [AccessedThroughProperty("txtDescription")]
        private TextBox _txtDescription;
        [AccessedThroughProperty("txtName")]
        private TextBox _txtName;
        private object designerPlaceholderDeclaration;

        public ProjectDescription()
        {
            base.Init += new EventHandler(this.Page_Init);
            this._ProjectId = -1;
        }

        public void Initialize()
        {
            this.dropProjectManager.DataSource = ITUser.GetAllUsers();
            this.dropProjectManager.DataBind();
            if (this.ProjectId != -1)
            {
                Project projectToUpdate = Project.GetProjectById(this.ProjectId);
                if (projectToUpdate != null)
                {
                    this.txtName.Text = projectToUpdate.Name;
                    this.txtDescription.Text = projectToUpdate.Description;
                    this.dropProjectManager.SelectedValue = projectToUpdate.ManagerId;
                    this.dropProjectManager.RemoveDefault();
                }
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        public bool Update()
        {
            if (this.Page.IsValid)
            {
                Project newProject = new Project(this.ProjectId, this.txtName.Text.Trim(), this.txtDescription.Text.Trim(), this.dropProjectManager.SelectedValue, this.Page.User.Identity.Name);
                if (newProject.Save())
                {
                    this._ProjectId = newProject.Id;
                    return true;
                }
                this.lblError.Text = "Could not save project";
            }
            return false;
        }

        int ASPNET.StarterKit.IssueTracker.UserInterfaceLayer.IEditProjectControl.ProjectId
        {
            get
            {
                return this._ProjectId;
            }
            set
            {
                this._ProjectId = value;
            }
        }

        protected virtual PickSingleUser dropProjectManager
        {
            get
            {
                return this._dropProjectManager;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropProjectManager != null)
                {
                }
                this._dropProjectManager = value;
                if (this._dropProjectManager != null)
                {
                }
            }
        }

        protected virtual Label lblError
        {
            get
            {
                return this._lblError;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lblError != null)
                {
                }
                this._lblError = value;
                if (this._lblError != null)
                {
                }
            }
        }

        public int ProjectId
        {
            get
            {
                return this._ProjectId;
            }
            set
            {
                this._ProjectId = value;
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator1
        {
            get
            {
                return this._RequiredFieldValidator1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator1 != null)
                {
                }
                this._RequiredFieldValidator1 = value;
                if (this._RequiredFieldValidator1 != null)
                {
                }
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator2
        {
            get
            {
                return this._RequiredFieldValidator2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator2 != null)
                {
                }
                this._RequiredFieldValidator2 = value;
                if (this._RequiredFieldValidator2 != null)
                {
                }
            }
        }

        protected virtual TextBox txtDescription
        {
            get
            {
                return this._txtDescription;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtDescription != null)
                {
                }
                this._txtDescription = value;
                if (this._txtDescription != null)
                {
                }
            }
        }

        protected virtual TextBox txtName
        {
            get
            {
                return this._txtName;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtName != null)
                {
                }
                this._txtName = value;
                if (this._txtName != null)
                {
                }
            }
        }
    }
}

